//
//  BillViewController.m
//  jingdongfang
//
//  Created by 郝志宇 on 16/8/11.
//  Copyright © 2016年 ZhiYu Hao. All rights reserved.
//

#import "BillViewController.h"
#import "BillTableViewCell.h"
#import "IGWalletBillApi.h"
#import "IGWalletBillDetail.h"

@interface BillViewController () <UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *table;
@property (nonatomic, strong)IGWalletBillApi *walletBillApi;
@property(nonatomic,strong)NSArray *dataArray;

@end

@implementation BillViewController
#pragma mark -懒加载
-(NSArray *)dataArray{
    if (!_dataArray) {
        _dataArray=[NSArray array];
    }
    return _dataArray;
}
#pragma mark -生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
//    self.title = @"账单详情";
    self.title = NSLocalizedString(@"Bill Details", nil);
    self.table.backgroundColor=[UIColor c2Color];
    self.table.separatorInset = UIEdgeInsetsMake(0, KSCREENWIDTH, 0, 0);
    self.walletBillApi=[[IGWalletBillApi alloc]initWithUId:[IGUser getUid]];
    [self dataRequest];
}
-(void)dataRequest{
      @KWeakObj(self)
    [self.walletBillApi startWithDecodeClass:[IGWalletBillResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        [self.table ig_endHeaderRefreshing];
        [self.table ig_endFooterRefreshing];
        if (responseObject) {
            IGWalletBillResp *resp=responseObject;
            IGWalletBillModel *model=resp.data;
            selfWeak.dataArray=model.capitalFlow;
            if (model.capitalFlow && model.capitalFlow.count > 0)
            {
                _dataArray=[NSArray arrayWithArray:model.capitalFlow];
                [self.table ig_isHeaderRefreshing ];
            }
            else
            {
                [self.table ig_endFooterRefreshingWithNoMoreData];
            }
            [selfWeak.table reloadData];
        }
    }];
    
}


#pragma mark — UITableViewDelegate, UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BillTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"billCell"];
    if (cell==nil) {
        cell = [[BillTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"billCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    IGWalletBillDetail *model=self.dataArray[indexPath.row];
    cell.data=model;
    [cell setNeedsLayout];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 65;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    CapitalFlow *info = billModel.recommends[indexPath.row];
//    if ([info.types integerValue]==3 && [info.type isEqualToString:@"1"])
//    {
////        [self loadDataWithId:info.o_id];
//    }
}
- (void)jumpPageWithUserId:(NSString *)userId
{
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = backBarButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//- (void)shaxuan:(UIBarButtonItem *)sender
//{
//    [self presentMessageTips:@"点击筛选"];
//}

@end
